package xyz.xtgl.oauth2.config;

import xyz.xtgl.oahth2.config.properties.CustomizeProperties;
import xyz.xtgl.oauth2.config.helper.CustomJwtAccessTokenConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.CustomJwtTokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;

@Configuration
public class TokenConfig {

    @Bean
    public CustomizeProperties customizeProperties(){
        return new CustomizeProperties();
    }

    // 令牌存储策略
    @Bean
    public TokenStore tokenStore(){
        // Jwt令牌存储方案
        return new CustomJwtTokenStore(assessTokenConverter());
    }
    @Bean
    public JwtAccessTokenConverter assessTokenConverter() {
        CustomJwtAccessTokenConverter converter = new CustomJwtAccessTokenConverter();
        converter.setSigningKey(customizeProperties().getOauth2().getJwt().getSigningKey());//
        return converter;
    }

}
